var xmlhttp;

function getXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return xmlhttp;
}

function addTag()
{
	getXmlHttpObject();
	var tagname = document.getElementById("tagname").value;
	var supertag = document.getElementById("supertag").value;
	
	var url = "../controllers/addTagController.php";
	var params = "tagname=" + tagname + "&supertag=" + supertag; 
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = addTagSuccess;
	xmlhttp.send(params);
}

function addTagSuccess()
{
	if (xmlhttp.readyState == 4)
		if (xmlhttp.status == 200)
		{
			window.location.reload(); 
		}
	    else if (request.status == 404)
	        alert("请求的链接不存在");
	    else
	        alert("错误: 错误代码 " + xmlhttp.status);
}

function deleteTag(tagId)
{
	getXmlHttpObject();
	var url = "../controllers/deleteTagController.php";
	var params = "tagId=" + tagId; 
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = deleteTagSuccess;
	xmlhttp.send(params);
}

function deleteTagSuccess()
{
	if (xmlhttp.readyState == 4)
		if (xmlhttp.status == 200)
		{

			window.location.reload(); 
		}
	    else if (request.status == 404)
	        alert("请求的链接不存在");
	    else
	        alert("错误: 错误代码 " + xmlhttp.status);
}
